/*
 *  Copyright (c) 2022 ZhuHai Jieli Technology Co.,Ltd.
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

#ifndef _LP_TIMER_H_
#define _LP_TIMER_H_

#include "typedef.h"

bool __hw_nv_timer_set_time(u8 index, u32 usec);

u32 __hw_nv_timer_get_stc(u8 index, u8 virtual_rtc_flag);

u32 __hw_nv_timer_get_time(u8 index, u8 index2);

u32 __hw_nv_timer_get_pass_time(u8 index, u8 virtual_rtc_flag);

u32 __hw_nv_timer_get_period(u8 index, u8 virtual_rtc_flag);

bool __hw_nv_timer0_set_time(u32 usec);

void __hw_nv_timer0_init(void);

bool __hw_nv_timer_is_runnig(u8 index);

void __hw_nv_timer1_enable(void);

void __hw_nv_timer1_disable(void);

bool __hw_nv_timer0_reset_time(u32 usec);

bool __hw_nv_timer1_reset_time(u32 usec);

bool __hw_nv_timer1_set_time(u32 usec);

void __hw_nv_timer1_init(void);

void __hw_nv_timer0_dump(void);

void rtc_hw_nv_timer1_init(u8 osc_type, u32 osc_hz, u16 interval);

void rtc_nv_timer1_sleep_init(void);

void __hw_nv_timer0_hw_kick_start(void);

void __hw_nv_timer0_sw_kick_start(void);

void __hw_nv_timer0_disable(void);

void __hw_nv_timer0_enable(void);

void hw_nv_timer1_reset_time(u32 usec);

#define NV_TIMER0_GET_TIME()        __hw_nv_timer_get_time(PD_LP0_CNT_READ, P3_LP_PRD00)
#define NV_TIMER1_GET_TIME()        __hw_nv_timer_get_time(PD_LP1_CNT_READ, P3_LP_PRD10)
#define NV_TIMER0_GET_STC()         __hw_nv_timer_get_stc(PD_LP0_STC_READ, 0)
#define NV_TIMER1_GET_STC()         __hw_nv_timer_get_stc(PD_LP1_STC_READ, 0)

#define NV_TIMER0_GET_PASS_TIME()    __hw_nv_timer_get_pass_time(PD_LP0_CNT_READ, 0)    // us
#define NV_TIMER1_GET_PASS_TIME()    __hw_nv_timer_get_pass_time(PD_LP1_CNT_READ, 0)    // us

#define NV_TIMER0_GET_PREIOD()      __hw_nv_timer_get_period(P3_LP_PRD00, 0)    // us
#define NV_TIMER1_GET_PREIOD()      __hw_nv_timer_get_period(P3_LP_PRD10, 0)    // us

#endif

